<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <script type="text/javascript" src="/jquery/jquery-2.2.4.min.js"></script>
    <script type="text/javascript" src="/js/util.js"></script>
    <title>新人大礼包</title>
</head>
<style scoped>
    body {
        margin: 0;
    }

    .register {
        max-width: 720px;
        min-width: 320px;
        width: 100%;
        /*height: 150%;*/
        left: 50%;
        transform: translateX(-50%);
        top: 0;
        /*bottom: 0;*/
        overflow: hidden;
        position: absolute;
        background: url("/static/image/inviteNewImg/res_bg.png") no-repeat;
        background-size: 100% 100%;
        padding-bottom: 20px;
    }

    .bg img {
        width: 100%;
        height: 100%;
    }

    .res_detail {
        position: relative;
        z-index: 100;
        left: 0;
        right: 0;
        top: 31px;
        bottom: 50px;
        text-align: center;
        animation: zoomIn 0.8s ease-out;
    }

    .title_img {
        margin: 0 auto;
    }

    .res_detail .res_title {
        display: inline-block;
        width: 80%;
        margin: 0 auto;
    }

    .res_detail .res_tip {
        width: 50%;
        margin: 10px auto 0;
    }

    .input_box {
        /*width: 5.32rem;*/
        width: 80%;
        margin: 30px auto 0;
    }

    .input_box .line {
        margin: 12px 0;
    }

    .input_tip {
        display: none;
        position: fixed;
        left: 48%;
        top: 40%;
        min-width: 60%;
        margin-left: -30%;
        border-radius: 4px;
        background: rgba(1, 1, 1, 0.6);
        color: #fff;
        padding: 0 10px;
        line-height: 40px;
        animation: zoomIn .3s 0.1s 1 both;
    }

    .res_detail p {
        display: flex;
        align-items: center;
        width: 100%;
        text-align: center;
        border-radius: 30px;
        height: 74px;
        background: #fff;
        margin: 0;
        box-shadow: 0 3px 16px 0 rgba(249, 4, 4, 0.8);
        overflow: hidden;
    }

    .res_detail p .img_phone {
        width: 32px;
        height: 26px;
        margin-left: 7px;
    }

    .res_detail p .img_lock {
        width: 20px;
        height: 19px;
        margin-left: 15px;
    }

    .res_detail p .img_code {
        width: 20px;
        height: 24px;
        position: absolute;
        left: 12px;
        top: 0;
        bottom: 0;
        margin: auto;
    }

    .res_detail p #phone {
        padding: 0 8px 0 0;
    }

    .res_detail p input {
        border: none;
        padding: 0 8px;
        width: 100%;
        height: 100%;
        line-height: 45px;
        outline: none;
        font-size: 26px;
        color: #2f2f2f;
    }

    .res_detail .line:nth-child(2) p {
        background: none;
        box-shadow: none;
        display: block;
    }

    .res_detail p .ver_code {
        float: left;
        width: 46%;
        height: 100%;
        line-height: 37px;
        border-radius: 30px;
        text-align: center;
        box-shadow: 0 3px 16px 0 rgba(249, 4, 4, 0.8);
    }

    .res_detail p span {
        float: right;
        display: inline-block;
        width: 46%;
        height: 100%;
        line-height: 74px;
        border-radius: 30px;
        text-align: center;
        background: linear-gradient(#ffe108, #ffb41b);
        box-shadow: 0 3px 16px 0 rgba(249, 4, 4, 0.8);
        color: #fff;
        font-size: 16px;
    }

    .submit {
        display: block;
        width: 90%;
        height: 50px;
        line-height: 50px;
        margin: 22px auto;
        text-align: center;
        color: #ffffff;
        font-size: 16px;
        border-radius: 30px;
        letter-spacing: 1px;
        background: linear-gradient(#ffe108, #ffb41b);
        box-shadow: 0 3px 16px 0 rgba(249, 111, 12, 0.8);
    }

    @media only screen and (max-width: 720px) {
        .res_detail p {
            height: 55px;
            line-height: 55px;
        }

        .res_detail p input {
            font-size: 16px;
        }

        .res_detail p span {
            font-size: 16px;
            line-height: 55px;
        }
    }

    @media only screen and (max-width: 640px) {
        .res_detail p {
            height: 42px;
            line-height: 42px;
        }

        .res_detail p input {
            font-size: 14px;
            height: 42px;
            line-height: 42px;
        }

        .res_detail p span {
            font-size: 14px;
            line-height: 42px;
        }
    }

    @media only screen and (max-width: 414px) {
        .res_detail p {
            height: 37px;
            line-height: 37px;
        }

        .res_detail p input {
            font-size: 12px;
            height: 37px;
            line-height: 37px;
            width: 45%;
        }

        .res_detail p span {
            font-size: 12px;
            line-height: 37px;
            width: 45%;
        }
    }

    @media only screen and (max-width: 360px) {
        .res_detail p {
            height: 35px;
            line-height: 35px;
        }

        .res_detail p input {
            height: 35px;
            line-height: 35px;
        }

        .res_detail p span {
            line-height: 35px;
        }
    }
</style>
<body>
<div class="register">
    <div class="res_detail">
        <div class="title_img">
            <img class="res_title" src="/image/inviteNewImg/res_title.png">
            <img class="res_tip" src="/image/inviteNewImg/res_tip.png">
        </div>
        <!--用户信息-->
        <div class="input_box">
            <div class="line">
                <p>
                    <img src="/image/inviteNewImg/phone.png" class="img_phone">
                    <input type="text" id="phone" value="${phone!''}" placeholder="请输入手机号">
                </p>
            </div>
            <div class="line" style="position: relative">
                <p>
                    <img src="/image/inviteNewImg/vercode.png" class="img_code">
                    <input type="text" class="ver_code" id="vercode" placeholder="请输入验证码">
                    <span id="get_time" onclick="getCode()">获取验证码</span>
                    <span id="time" style="display: none"></span>
                </p>
            </div>
            <div class="line">
                <p>
                    <img src="/image/inviteNewImg/lock.png" class="img_lock">
                    <input type="password" id="password" placeholder="请输入密码">
                </p>
            </div>
            <span class="input_tip" id="tip">wrwrwrw</span>
            <span class="submit" onclick="requestSub()">立即注册</span>
        </div>
        <!--活动规则-->
        <div class="rule">
            <iframe align="center" width="100%" height="400px" src="/invite/rule" frameborder="no" border="0"
                    marginwidth="0" marginheight="0" scrolling="no"></iframe>
        </div>
    </div>
</div>
</body>
<script>

    let category = "${category!''}";
    let app = "${app!''}";
    let inviteCode = "${inviteCode!''}";

    document.body.style.fontSize = '14px';
    let deviceWidth = document.documentElement.clientWidth;
    if (deviceWidth > 720) {
        deviceWidth = 720;
        document.documentElement.style.fontSize = deviceWidth / 6.4 + 'px';
    }

    // 错误提示
    function setTip() {
        let set_time = 3;
        let tips = document.getElementById('tip');
        tips.style.display = 'block';
        let authTime = setInterval(() => {
            set_time--;
            if (set_time <= 0) {
                tips.style.display = 'none';
                clearInterval(authTime);
            }
        }, 1000);
    }

    // 发起请求
    function requestSub() {
        let password = document.getElementById('password').value;
        let code = document.getElementById('vercode').value;
        let phone = document.getElementById('phone').value;
        let tip = document.getElementById('tip');
        let phPattern = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
        let codePattern = /^\d{4}$/
        let uPattern = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z_]{6,16}$/;
        if (!phPattern.test(phone)) {
            tip.innerText = '手机号错误，请重新输入!';
            setTip()
            return;
        } else if (!codePattern.test(code)) {
            tip.innerText = '验证码错误，请重新输入!';
            setTip();
            return;
        } else if (!uPattern.test(password)) {
            tip.innerText = '密码必须由6~16位的数字、字母组合!';
            setTip();
            return;
        } else {
            $.ajax({
                url: '/invite/register',
                type: 'post',
                data: {
                    category: category,
                    app: app,
                    inviteCode: inviteCode,
                    phone: phone,
                    code: code,
                    password: password
                },
                async: false,
                error: function () {
                },
                success: function (arg) {
                    if (arg.success) {
                        window.location.href = "/invite/download?type=1&phone=" + phone + "&inviteCode=" + inviteCode;
                    } else {
                        tip.innerText = arg.message;
                        setTip();
                        if (arg.status == "555") {
                            window.location.href = "/invite/download?type=2&phone=" + phone + "&inviteCode=" + inviteCode;
                        }

                    }
                }
            });
        }
    }


    // 获取验证码
    function getCode() {

        let phone = $("#phone").val();
        let tip = document.getElementById("tip");
        let phPattern = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
        if (!phPattern.test(phone)) {
            tip.innerText = '手机号错误，请重新输入!';
            setTip();
        } else {
            $.ajax({
                url: '/invite/register/code',
                type: 'post',
                data: {category: category, app: app, inviteCode: inviteCode, phone: phone},
                async: false,
                error: function () {
                },
                success: function (arg) {
                    if (arg.success) {
                        tip.innerText = arg.message;
                        setTip();
                        let time = document.getElementById('time');
                        let get = document.getElementById('get_time');
                        let get_time = arg.data;
                        time.style.display = 'block';
                        time.innerText = get_time + 's';
                        get.style.display = 'none';
                        tip.innerText = '';
                        let authTimetimer = setInterval(() => {
                            get_time--;
                            time.innerText = get_time + 's';
                            if (get_time <= 0) {
                                time.style.display = 'none';
                                get.style.display = 'block';
                                time.innerText = '获取验证码';
                                clearInterval(authTimetimer);
                            }
                        }, 1000);
                    } else {
                        tip.innerText = arg.message;
                        setTip();
                        if (arg.status == "555") {
                            window.location.href = "/invite/download?type=2&phone=" + phone + "&inviteCode=" + inviteCode;
                        }

                    }
                }
            });
        }
    }
</script>

</html>
